package com.thoughtworks.videorental.action;

import static org.junit.Assert.*;
import static org.mockito.Matchers.*;
import static org.mockito.Mockito.*;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Set;

import org.junit.Before;
import org.junit.Test;

import com.thoughtworks.videorental.domain.Customer;
import com.thoughtworks.videorental.domain.Rental;
import com.thoughtworks.videorental.domain.Transaction;
import com.thoughtworks.videorental.domain.repository.TransactionRepository;

public class ViewHistoryActionTest {
	
	private TransactionRepository mockTransactionRepository;
	ViewHistoryAction viewHistoryAction;
	

	@Before
	public void setUp() throws Exception {
		mockTransactionRepository = mock(TransactionRepository.class);
		viewHistoryAction = new ViewHistoryAction(mockTransactionRepository);
		
		
	}


	@Test
	public void testAreWeGettingTheTransactionsForTheCustomer() throws Exception{
		//Given
		Customer customer = new Customer("someuser","someuser","somepassword");
		viewHistoryAction.setCustomer(customer);
		Collection<Transaction> transactions = new ArrayList<Transaction>();
		when(mockTransactionRepository.transactionsBy(customer)).thenReturn(transactions);
		
		//When
		viewHistoryAction.execute();
		
		//Then
		assertEquals(transactions, viewHistoryAction.getTransactions());    
	}
	
	

}
